package com.polaris.live.adapter

import android.text.TextUtils
import android.view.View
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.polaris.live.R
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.databinding.ItemRoomInvitationBinding
import com.polaris.live.resp.back_resp.LiveInviteJoinUserResp
import com.polaris.live.utils.image.ImageUtils

/**
 * BackPackBubbleAdapter
 *
 * @author Created by 半仙 on 2024/1/31/031 11:44
 */
class RoomInvitationAdapter : BaseBindingAdapter<ItemRoomInvitationBinding, LiveInviteJoinUserResp>() {

    private var mSelectIndex = -1

    init {
        addChildClickViewIds(R.id.invite_rl, R.id.ok_rl)
    }

    override fun convert(
        holder: VBViewHolder<ItemRoomInvitationBinding>,
        item: LiveInviteJoinUserResp,
    ) {
        holder.vb.apply {
            Glide.with(context)
                .load(ImageUtils.imgPathSmall(item.user.avatar))
                .transform(CircleCrop())
                .into(avater)
            name.text = item.user.nickname
            vipView.setVipLevel(item.user.vipLevel)
            if (TextUtils.isEmpty(item.user.country)) {
                userCountry.visibility = View.GONE
            } else {
                userCountry.visibility = View.VISIBLE
                userCountry.setCountry(item.user.country)
            }
            levelView.setRichCharmBySexLevel(
                item.user.sex,
                item.user.richs,
                item.user.charms
            )
            if (item.invited) {
                inviteRl.visibility = View.GONE
                okRl.visibility = View.VISIBLE
            } else {
                inviteRl.visibility = View.VISIBLE
                okRl.visibility = View.GONE
            }

        }
    }

    fun setSelect(position: Int) {
        mSelectIndex = position

        notifyItemChanged(mSelectIndex)
    }

}